package com.osce.score.controller;

import com.csce.domain.entity.score.ScoreExModel;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.score.IScoreExModelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考试模版表Controller
 *
 * @author zzx
 * @since 2023-08-22
 */
@RestController
@RequestMapping("/score/ex_model")
public class ScoreExModelController extends BaseController {

    @Resource
    private IScoreExModelService scoreExModelService;

    /**
     * 查询考试模版表列表
     */
    @PreAuthorize("@ss.hasPermi('score:ex_model:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScoreExModel scoreExModel) {
        startPage();
        List<ScoreExModel> list = scoreExModelService.selectScoreExModelList(scoreExModel);
        return getDataTable(list);
    }

    /**
     * 导出考试模版表列表
     */
    @PreAuthorize("@ss.hasPermi('score:ex_model:export')")
    @Log(title = "考试模版表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoreExModel scoreExModel) {
        List<ScoreExModel> list = scoreExModelService.selectScoreExModelList(scoreExModel);
        ExcelUtil<ScoreExModel> util = new ExcelUtil<>(ScoreExModel.class);
        util.exportExcel(response, list, "考试模版表数据");
    }

    /**
     * 获取考试模版表详细信息
     */
    @PreAuthorize("@ss.hasPermi('score:ex_model:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(scoreExModelService.selectScoreExModelById(id));
    }

    /**
     * 新增考试模版表
     */
    @PreAuthorize("@ss.hasPermi('score:ex_model:add')")
    @Log(title = "考试模版表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoreExModel scoreExModel) {
        return toAjax(scoreExModelService.insertScoreExModel(scoreExModel));
    }

    /**
     * 修改考试模版表
     */
    @PreAuthorize("@ss.hasPermi('score:ex_model:edit')")
    @Log(title = "考试模版表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoreExModel scoreExModel) {
        return toAjax(scoreExModelService.updateScoreExModel(scoreExModel));
    }

    /**
     * 删除考试模版表
     */
    @PreAuthorize("@ss.hasPermi('score:ex_model:remove')")
    @Log(title = "考试模版表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(scoreExModelService.deleteScoreExModelByIds(ids));
    }
}
